package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.SystemLog;
import cn.wolfcode.crm.query.BillQueryObject;
import cn.wolfcode.crm.query.ObjectQuery;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.service.ISystemLogService;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collections;
import java.util.List;

@Controller
@RequestMapping("systemLog")
public class SystemLogController {
    @Autowired
    private ISystemLogService systemLogService;

    //用于跳转到日志页面
    @RequiresPermissions("systemLog:index")
    @PermissionName("日志主页")
    @RequestMapping("index")
    public String index(Model model) {
        BillQueryObject qo = new BillQueryObject();
        PageResult<SystemLog> query = systemLogService.query(qo);
        List<SystemLog> rows = query.getRows();
        Collections.reverse(rows);
        model.addAttribute("list",rows);
        return "systemLog/list";
    }


    @RequestMapping("list")
    @RequiresPermissions("systemLog:list")
     @PermissionName("日志列表")
    @ResponseBody
    public PageResult list(@ModelAttribute("qo") ObjectQuery qo) {
        //返回json格式的查询结果对象
        PageResult<SystemLog> list = systemLogService.query(qo);
        return list;
    }
}
